Repository navigation
Conversation
An excluded or VCS-ignored symlink inside a package was resolved before the exclusion check. If it pointed outside the project root, for example a broken link or a virtualenv's python, relative_to() raised and the build failed. Check the exclusion on the path inside the project before resolving it, and keep symlinks when collecting the files of an excluded directory, since is_file() is false for broken links and links to directories.
Linked issuesChecked at commit e216642 #8257 Trace on excluded broken symlinks · 1 of 1 met
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/poetry/core/masonry/builders/builder.py" line_range="105" />
<code_context>
def add_all_files(path: Path, target: set[str]) -> None:
all_files = (
- [f for f in path.glob("**/*") if f.is_file()]
+ [f for f in path.glob("**/*") if f.is_file() or f.is_symlink()]
if path.is_dir()
else [path]
</code_context>
<issue_to_address>
**Excluded directory links still fail**
When an explicit exclude glob matches a symlink to a directory inside a package, and that link points outside the project, `add_all_files` treats an excluded directory symlink as a directory and records only entries yielded by `glob`, not the symlink path itself. `is_excluded` therefore misses the link, and `BuildIncludeFile` resolves it outside the project and raises `ValueError` during the build.
Add the matched path itself to the exclusion set when it is a symlink, as well as collecting any descendants.
</issue_to_address>
### Comment 2
<location path="src/poetry/core/masonry/builders/builder.py" line_range="194" />
<code_context>
if file.is_dir():
if self.format in formats:
for current_file in file.glob("**/*"):
+ if self._is_excluded_unresolved(current_file):
+ continue
+
</code_context>
<issue_to_address>
**Explicitly included links disappear**
When an explicitly included directory is a symlink to a directory inside the project and VCS ignores the symlink path, `_is_excluded_unresolved()` treats the ignored symlink path as excluding every child, so the directory traversal skips files that an explicit include was meant to restore. The files disappear from the built package, unlike the prior resolved-path check.
Preserve explicit-include precedence in the unresolved-path check, or ensure the explicitly included symlink directory itself cancels the ignored parent entry.
</issue_to_address>
### Comment 3
<location path="tests/masonry/builders/test_sdist.py" line_range="688" />
<code_context>
+def test_sdist_excluded_symlinks(
+ excluded_symlinks: Path, mocker: MockerFixture
+) -> None:
+ mocker.patch(
+ "poetry.core.vcs.git.Git.get_ignored_files",
+ return_value=["excluded_symlinks/vcs_ignored"],
</code_context>
<issue_to_address>
**Git-ignored symlinks go untested**
When the fixture project is under pytest's ordinary `tmp_path`, outside a Git worktree, `get_vcs()` returns `None`, so the `Git.get_ignored_files` patches at these lines are never called. The final name-list assertions can still pass because the VCS case is a directory symlink that is not included as a file, so neither test detects broken VCS exclusion handling.
Make `get_vcs()` return a Git instance for these tests (or initialize a temporary repository) so the patched ignored-file list is actually used.
Also at `tests/masonry/builders/test_wheel.py:185`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/poetry/core/masonry/builders/builder.py:105, src/poetry/core/masonry/builders/builder.py:194, tests/masonry/builders/test_sdist.py:688
A VCS-ignored link to a directory that is explicitly included was dropped from the build: the explicitly included set held only the files below the link, so the link path stayed in the excluded set, and the new unresolved check skipped every file under it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves: python-poetry/poetry#8257
A symlink inside a package that points outside the project makes the build fail with
ValueError: '/dev/sdb' is not in the subpath of '...', even when the symlink is excluded withexcludeor ignored by git. The issue has broken links to/devin an excluded test directory. The same happens with a git-ignored virtualenv inside the package, whosebin/pythonlinks to the system interpreter, or with a git-ignored link to a data directory elsewhere.find_files_to_add()creates aBuildIncludeFilefor each path, which resolves symlinks, and only then checks the resolved path withis_excluded(). For a link that leaves the project,relative_to()raises before the exclusion is looked at. There is a second gap for an excluded directory such asexclude = ["foo/tests"]:find_excluded_files()collects its files withis_file(), which is false for a broken link or a link to a directory, so those links were not in the excluded set at all.The exclusion is now checked on the path inside the project before it is resolved, and
add_all_fileskeeps symlinks. The existing check on the resolved path stays, so nothing that was excluded before gets included now. A link that leaves the project and is not excluded still fails as before; whether such links should be followed is a separate question (python-poetry/poetry#9982).A matched link to a directory is also added to the excluded or included set itself, not only the files below it. Without that, an explicitly included directory link that git ignores, such as
include = [{ path = "foo/assets" }]withfoo/assetsin.gitignore, would lose its files to the new check, although main packages them. One case does change: a git-ignored link to a file inside the project, such asfoo/link.txt -> ../shared/x.txtin a package, was packaged on main at its resolved pathshared/x.txtand is now left out, as its ignore rule says.test_wheel_excluded_symlinksandtest_sdist_excluded_symlinksbuild a project with a broken link and a directory link under an excluded directory, plus a git-ignored link to a directory outside the project, and check that only__init__.pyends up in the package. On main both fail withValueError: '.../missing' is not in the subpath of '.../excluded_symlinks', and they also fail when either of the two changes is reverted on its own.test_sdist_explicitly_included_vcs_ignored_dir_symlinkcovers the included directory link and fails without the second commit. The tests skip if symlinks cannot be created, which can happen on Windows.The unit tests pass on CPython 3.11, 3.13 and 3.14 in Linux containers (2957 passed, 7 skipped), and so do the integration tests on 3.13, mypy and the pre-commit hooks. I also built the layout from the issue (
exclude = ["foo/tests/**"]with a link to/dev/sdb) withbuild_sdistandbuild_wheelon 3.11 to 3.14: it failed on main and builds now. I did not run anything on Windows or macOS.